﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Principal;
using System.Text;
using System.Windows.Forms;

namespace Futajma.MigrationStudio.SharePointPersistance
{
    public static class CredentialManager
    {
        static NetworkCredential _credentials;
        static bool _initialized = false;

        public static NetworkCredential Credentials        
        { 
            get
            {
                return _credentials;
            }
          set
          {
              _credentials = value;
              _initialized = true;
          } 
        }

        public static new string ToString()
        {
            if (_initialized)
            {
                return string.Format(@"{0}\{1}", Credentials.Domain, Credentials.UserName);
            }
            else
            {
                return WindowsIdentity.GetCurrent().Name;
            }
        }

        static CredentialManager()
        {
            CredentialManager._credentials = CredentialCache.DefaultNetworkCredentials;
        }

    }
}
